import requests
citycode=0
data_dict={}
url = 'https://gaode.com/service/cityList?version=2021111710'
header = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43',
    'cookie': 'cna=ckFXGa8kjXECASeyIrb/Y8VH; xlly_s=1; UM_distinctid=17d9dfb0243317-08e4237ae85bf5-59191459-e1000-17d9dfb024516d; _uab_collina=163903301462640921701681; CNZZDATA1255626299=1440308117-1639032214-https%253A%252F%252Fcn.bing.com%252F%7C1639032214; isg=BD4-TZ3w01hsUQd8sAYIP8Aij1SAfwL5nYd4NOhEvgF8i95lUQ6SCb8qAldHifoR; l=eBI2gxJHgkUEseqxBO5Bnurza779uQOb4-VzaNbMiInca6sP_FOJNNCdlAZH8dtxgtCfueKzyZKj_RLHR3jR2xDDB0KbAd2jfxvO.; tfstk=cdCGBbML6OJ_bvJhF5O1JJ0-vpCGagZwbs5OT_PrpWMFHl5B7sDsLYRTpyxUVlkf.'
}
proxies = {'http': 'http://183.236.232.160:8080'}
response = requests.get(url)
data = response.json()['data']['cityByLetter']
word = input('输入你想要查询的城市: ')
# print(data.keys())#dict_keys(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z'])
for item in data.keys():
    for i in data[item]:
        if i['name'] == word:
            citycode = i['adcode']
# print(citycode)
next_url_demo = 'https://gaode.com/service/weather'
param={'adcode':citycode}
target_html = requests.get(next_url_demo,params=param)
data1=target_html.json()['data']['data'][0]
data_dict['最低温']=data1['forecast_data'][0]['min_temp']
data_dict['最高温']=data1['forecast_data'][0]['max_temp']
data_dict['天气']=data1['forecast_data'][0]['weather_name']
print(data_dict)
    


